unit ApplicationSettings;

{$mode objfpc}{$H+}

//========================================================================================
//
// Unit :
//
// Description :
//
// Called By : ASLDataModule : ConnectASLDB
//             FeedintCategoryTable : CreateFeedingCategoryTable
//             HUtils : HUBoolToStr
//             Init : Initialize
//
// Calls : TankTable
//
//
// Ver. : 1.0.0
//
// Date : 6 Nov 2016
//
//========================================================================================

interface

uses
  Buttons, Classes, ComCtrls, Dialogs, ExtCtrls, FileUtil, Forms, Graphics, INIFiles,
  SysUtils, StdCtrls, Controls,
  // Application Units
  HUtils;

const
  tLengthUnitArrayMaxEntries = 1;
  tTemperatureUnitArrayMaxEntries = 1;
  tVolumeUnitArrayMaxEntries = 1;

type

  tLengthUnit = (luInch, luCM);
  tLengthUnitArray = array[0..tLengthUnitArrayMaxEntries] of string;
  tTemperatureUnit = (tuDegF, tuDegC);
  tTemperatureUnitArray = array[0..tTemperatureUnitArrayMaxEntries] of string;
  tVolumeUnit = (vuGallon, vuLiter);
  tVolumeUnitArray = array[0..tVolumeUnitArrayMaxEntries] of string;

  { TfrmSettings }

  TfrmSettings = class(TForm)
    bbtCancel: TBitBtn;
    bbtSave: TBitBtn;
    bbtHelp: TBitBtn;
    bbtASLPathBrowse: TBitBtn;
    cbxDefaultLengthUnit: TComboBox;
    cbxDefaultTemperatureUnit: TComboBox;
    chkAutoloadLastTank: TCheckBox;
    cbxDefaultTankType: TComboBox;
    cbxDefaultVolumeUnit: TComboBox;
    cbxDefaultTankLengthUnit: TComboBox;
    cbxDefaultTankTemperatureUnit: TComboBox;
    cbxDefaultTankVolumeUnit: TComboBox;
    edtASLDataPath: TEdit;
    edtApplicationPath: TEdit;
    edtASLPath: TEdit;
    edtASLTanksPath: TEdit;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    GroupBox3: TGroupBox;
    Label1: TLabel;
    StaticText1: TStaticText;
    StaticText2: TStaticText;
    StaticText3: TStaticText;
    StaticText4: TStaticText;
    StaticText5: TStaticText;
    StaticText6: TStaticText;
    StaticText7: TStaticText;
    stxDefauktLengthUnit1: TStaticText;
    stxDefauktVolumeUnit1: TStaticText;
    stxDefaultTankType: TStaticText;
    stxDefaultTemperatureUnit: TStaticText;
    tshSettings: TPageControl;
    ts1AppData: TTabSheet;
    ts2TankData: TTabSheet;
    procedure bbtCancelClick(Sender: TObject);
    procedure bbtSaveClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
      { private declarations }
    fApplicationName : string;
    fApplicationVersion : string;
    fApplicationDate : string;
    fApplicationPath : string;
    fASLPath : string;
    fASLDataPath : string;
    fASLTanksPath : string;
    fAutoLoadLastTank : boolean;
    fLastTank : string;
    fDefaultLengthUnit : tLengthUnit;
    fDefaultTemperatureUnit : tTemperatureUnit;
    fDefaultVolumeUnit : tVolumeUnit;

  public
    { public declarations }
    const
      LengthUnitArray: tLengthUnitArray = ('Inches', 'Centimeters');
      TemperatureUnitArray: tTemperatureUnitArray = ('Degrees F', 'Degrees C');
      VolumeUnitArray: tVolumeUnitArray = ('Gallons', 'Litres');

    function GetApplicationName: string;
    procedure SetApplicationName (strName:string);
    function GetApplicationVersion: string;
    procedure SetApplicationVersion (strVersion:string);
    function GetApplicationDate: string;
    procedure SetApplicationDate (strDate:string);
    function GetApplicationPath: string;
    procedure SetApplicationPath (strPath:string);
    function GetASLDataPath: string;
    procedure SetASLDataPath (strPath:string);
    function GetASLPath: string;
    procedure SetASLPath (strPath:string);
    function GetASLTanksPath: string;
    procedure SetASLTanksPath (strPath:string);
    function GetAutoLoadLastTank : boolean;
    procedure SetAutoLoadLastTank (vblnAutoLoad: boolean);
    function GetLastTank : string;
    procedure SetLastTank (vstrLastTank: string);
    function GetDefaultLengthUnit : tLengthUnit;
    function GetDefaultLengthUnitStr: string;
    procedure SetDefaultLengthUnit (vLengthUnit: tLengthUnit);
    procedure SetDefaultLengthUnitFromStr (strLengthUnit:string);
    function GetDefaultTemperatureUnit : tTemperatureUnit;
    function GetDefaultTemperatureUnitStr: string;
    procedure SetDefaultTemperatureUnit (vTemperatureUnit: tTemperatureUnit);
    procedure SetDefaultTemperatureUnitFromStr (strTemperatureUnit : string);
    function GetDefaultVolumeUnit : tVolumeUnit;
    function GetDefaultVolumeUnitStr: string;
    procedure SetDefaultVolumeUnit (vVolumeUnit: tVolumeUnit);
    procedure SetDefaultVolumeUnitFromStr (strVolumeUnit : string);
    function ASLSetupFileExists : boolean;
    procedure ReadASLSetupFile;
    function ASLSettingsFileExists : boolean;
    procedure ReadASLSettingsFile;
    procedure WriteASLSettingsFile;
  published
     property ApplicationName: string read GetApplicationName
                                        write SetApplicationName;
     property ApplicationVersion: string read GetApplicationVersion
                                        write SetApplicationVersion;
     property ApplicationDate: string read GetApplicationDate
                                        write SetApplicationDate;
     property ApplicationPath: string read GetApplicationPath
                                        write SetApplicationPath;
     property ASLPath: string read GetASLPath
                                        write SetASLPath;
     property ASLDataPath: string read GetASLDataPath
                                        write SetASLDataPath;
     property ASLTanksPath: string read GetASLTanksPath
                                        write SetASLTanksPath;
     property AutoLoadLastTank: boolean read GetAutoLoadLastTank
                                        write SetAutoLoadLastTank;
     property LastTank: string read GetLastTank
                                        write SetLastTank;
     property DefaultLengthUnit: tLengthUnit read GetDefaultLengthUnit
                                        write SetDefaultLengthUnit;
     property DefaultTemperatureUnit: tTemperatureUnit read GetDefaultTemperatureUnit
                                        write SetDefaultTemperatureUnit;
     property DefaultVolumeUnit: tVolumeUnit read GetDefaultVolumeUnit
                                        write SetDefaultVolumeUnit;
  end;// TfrmSettings = class(TForm)

var
  frmSettings: TfrmSettings;

const
  cstrASLSetupFileName = 'ASLSetup.ini';
  cstrASLSettingsFileName = 'ASLSettings.ini';

implementation

{$R *.lfm}

uses
  TankTable;

var
  vluOrigDefaultLengthUnit : tLengthUnit;
  vtuOrigDefaultTemperatureUnit : tTemperatureUnit;
  vvuOrigDefaultVolumeUnit : tVolumeUnit;
  valOrigAutoloadLastTank : boolean;

  vttOrigDefaultTankType : tTankType;
  vluOrigDefaultTankLengthUnit : tLengthUnit;
  vtuOrigDefaultTankTemperatureUnit : tTemperatureUnit;
  vvuOrigDefaultTankVolumeUnit : tVolumeUnit;

//========================================================================================
//          PRIVATE ROUTINES
//========================================================================================

//========================================================================================
//          PUBLIC ROUTINES
//========================================================================================

//========================================================================================
//          PUBLISHED ROUTINES
//========================================================================================

//========================================================================================
//          PROPERTY ROUTINES
//========================================================================================
function TfrmSettings.GetApplicationName : string;
begin
  Result := fApplicationName;
end;// function TfrmSettings.GetApplicationName

//----------------------------------------------------------------------------------------
procedure TfrmSettings.SetApplicationName (strName:string);
begin
  fApplicationName := strName;
end;// procedure TfrmSettings.SetApplicationName

//========================================================================================
function TfrmSettings.GetApplicationVersion : string;
begin
  Result := fApplicationVersion;
end;// function TfrmSettings.GetApplicationVersion

//----------------------------------------------------------------------------------------
procedure TfrmSettings.SetApplicationVersion (strVersion:string);
begin
  fApplicationVersion := strVersion;
end;// procedure TfrmSettings.SetApplicationVersion

//========================================================================================
function TfrmSettings.GetApplicationDate : string;
begin
  Result := fApplicationDate;
end;// function TfrmSettings.GetApplicationDate

//----------------------------------------------------------------------------------------
procedure TfrmSettings.SetApplicationDate (strDate:string);
begin
  fApplicationDate := strDate;
end;// procedure TfrmSettings.SetApplicationDate

//========================================================================================
function TfrmSettings.GetApplicationPath : string;
begin
  Result := fApplicationPath;
end;// function TfrmSettings.GetApplicationPath

//----------------------------------------------------------------------------------------
procedure TfrmSettings.SetApplicationPath (strPath:string);
begin
  fApplicationPath := strPath +'\';
end;// procedure TfrmSettings.SetApplicationPath

//========================================================================================
function TfrmSettings.GetASLDataPath : string;
begin
  Result := fASLDataPath;
end;// function TfrmSettings.GetASLDataPath

//----------------------------------------------------------------------------------------
procedure TfrmSettings.SetASLDataPath (strPath:string);
begin
  fASLDataPath := strPath;
end;// procedure TfrmSettings.SetASLDataPath

//========================================================================================
function TfrmSettings.GetASLPath : string;
begin
  Result := fASLPath;
end;// function TfrmSettings.GetASLPath

//----------------------------------------------------------------------------------------
procedure TfrmSettings.SetASLPath (strPath:string);
begin
  fASLPath := strPath;
end;// procedure TfrmSettings.SetASLPath

//========================================================================================
function TfrmSettings.GetASLTanksPath : string;
begin
  Result := fASLTanksPath;
end;// function TfrmSettings.GetASLTanksPath

//----------------------------------------------------------------------------------------
procedure TfrmSettings.SetASLTanksPath (strPath:string);
begin
  fASLTanksPath := strPath;
end;// procedure TfrmSettings.SetASLTanksPath

//========================================================================================
function TfrmSettings.GetAutoLoadLastTank : boolean;
begin
  Result := fAutoLoadLastTank;
end;// function TfrmSettings.GetAutoLoadLastTank : boolean }

//----------------------------------------------------------------------------------------
procedure TfrmSettings.SetAutoLoadLastTank( vblnAutoLoad : boolean );
begin
  fAutoLoadLastTank := vblnAutoLoad;
end;// procedure TfrmSettings.SetAutoLoadLastTank

//========================================================================================
function TfrmSettings.GetLastTank : string;
begin
  Result := fLastTank;
end;// function TfrmSettings.GetLastTank : string }

//----------------------------------------------------------------------------------------
procedure TfrmSettings.SetLastTank( vstrLastTank : string );
begin
  fLastTank := vstrLastTank;
end;// procedure TfrmSettings.SetLastTank

//========================================================================================
function TfrmSettings.GetDefaultLengthUnit : tLengthUnit;
begin
  Result := fDefaultLengthUnit;
end;// TfrmSettings.GetDefaultLengthUnit

//----------------------------------------------------------------------------------------
function TfrmSettings.GetDefaultLengthUnitStr: string;
begin
  Result := LengthUnitArray[ord(DefaultLengthUnit)];
end;// function TfrmSettings.GetDefaultLengthUnitStr

//========================================================================================
procedure TfrmSettings.SetDefaultLengthUnit (vLengthUnit: tLengthUnit);
begin
  fDefaultLengthUnit := vLengthUnit;
end;// TfrmSettings.procedure SetDefaultLengthUnit

//----------------------------------------------------------------------------------------
procedure TfrmSettings.SetDefaultLengthUnitFromStr (strLengthUnit:string);
var
  vintTemp : integer;
begin
  for vintTemp := 0  to tLengthUnitArrayMaxEntries do
    if TfrmSettings.LengthUnitArray[vintTemp] = strLengthUnit then
      fDefaultLengthUnit := tLengthUnit(vintTemp);
end;// procedure TfrmSettings.SetDefaultLengthUnitFromStr

//----------------------------------------------------------------------------------------
function TfrmSettings.GetDefaultTemperatureUnit : tTemperatureUnit;
begin
  Result := fDefaultTemperatureUnit;
end;// function TfrmSettings.GetDefaultTemperatureUnit

//----------------------------------------------------------------------------------------
function TfrmSettings.GetDefaultTemperatureUnitStr: string;
begin
  Result := TemperatureUnitArray[ord(DefaultTemperatureUnit)];
end;// function TfrmSettings.GetDefaultTemperatureUnitFromStr

//========================================================================================
procedure TfrmSettings.SetDefaultTemperatureUnit (vTemperatureUnit: tTemperatureUnit);
begin
  fDefaultTemperatureUnit := vTemperatureUnit;
end;// TfrmSettings.procedure SetDefaultTemperatureUnit

//----------------------------------------------------------------------------------------
procedure TfrmSettings.SetDefaultTemperatureUnitFromStr (strTemperatureUnit:string);
var
  vintTemp : integer;
begin
  for vintTemp := 0  to tTemperatureUnitArrayMaxEntries do
    if TemperatureUnitArray[vintTemp] = strTemperatureUnit then
      fDefaultTemperatureUnit := tTemperatureUnit(vintTemp);
end;// procedure TfrmSettings.SetDefaultTemperatureUnitFromStr

//========================================================================================
function TfrmSettings.GetDefaultVolumeUnit : tVolumeUnit;
begin
  Result := fDefaultVolumeUnit;
end;// function TfrmSettings.GetDefaultVolumeUnit

//----------------------------------------------------------------------------------------
function TfrmSettings.GetDefaultVolumeUnitStr: string;
begin
  Result := VolumeUnitArray[ord(DefaultVolumeUnit)];
end;// function TfrmSettings.GetDefaultVolumeUnitFromStr

//========================================================================================
procedure TfrmSettings.SetDefaultVolumeUnit (vVolumeUnit: tVolumeUnit);
begin
  fDefaultVolumeUnit := vVolumeUnit;
end;// procedure TfrmSettings.SetDefaultVolumeUnit

//----------------------------------------------------------------------------------------
procedure TfrmSettings.SetDefaultVolumeUnitFromStr (strVolumeUnit:string);
var
  vintTemp : integer;
begin
  for vintTemp := 0  to tVolumeUnitArrayMaxEntries do
    if VolumeUnitArray[vintTemp] = strVolumeUnit then
      fDefaultVolumeUnit := tVolumeUnit(vintTemp);
end;// procedure TfrmSettings.SetDefaultVolumeUnitFromStr

//========================================================================================
//          SUPPORT ROUTINES
//========================================================================================

//========================================================================================
//          MENU ROUTINES
//========================================================================================

//========================================================================================
//          FILE ROUTINES
//========================================================================================
const

  cstrSectionInstallSettings = 'INSTALL SETTINGS';
  cstrKeyASLPath = 'ASL Path';
  cstrKeyASLDataPath = 'ASL Data Path';
  cstrKeyASLTanksPath = 'ASL Tanks Path';
  cstrKeyAutoloadLastTank = 'Autoload Last Tank';
  cstrKeyLastTank = 'Last Tank';

  cstrSectionApplication = 'APPLICATION';
  cstrKeyDefaultLengthUnit = 'Default Length Unit';
  cstrKeyDefaultTemperatureUnit = 'Default Temperature Unit';
  cstrKeyDefaultVolumeUnit = 'Default Volume Unit';
  cstrSectionTankData = 'TANK DATA';
  cstrKeyDefaultTankType = 'Default Tank Type';
  cstrKeyDefaultTankLengthUnit = 'Default Tank Length Unit';
  cstrKeyDefaultTankTemperatureUnit = 'Default Tank Temperature Unit';
  cstrKeyDefaultTankVolumeUnit = 'Default Tank Volume Unit';

var
  ASLSetupFile : TINIFile;
  vstrASLSetupFileName : string;
  ASLSettingsFile : TINIFile;
  vstrASLSettingsFileName : string;

//========================================================================================
function TfrmSettings.ASLSetupFileExists : boolean;
var
  vstrTStr : string;
begin
  vstrASLSetupFileName := ApplicationPath + cstrASLSetupFileName;
  Result := FileExists(vstrASLSetupFileName);
end;// function ASLSetupFileExists

//========================================================================================

procedure TfrmSettings.ReadASLSetupFile;
begin

  vstrASLSetupFileName := ApplicationPath + cstrASLSetupFileName;

  ASLSetupFile := TINIFile.Create(vstrASLSetupFileName);

  // INSTALL SETTINGS Section
  ASLPath := ASLSetupFile.ReadString( cstrSectionInstallSettings,
                                        cstrKeyASLPath,
                                        ASLPath);

  ASLDataPath := ASLSetupFile.ReadString( cstrSectionInstallSettings,
                                        cstrKeyASLDataPath,
                                        ASLDataPath);

  ASLTanksPath := ASLSetupFile.ReadString( cstrSectionInstallSettings,
                                        cstrKeyASLTanksPath,
                                        ASLTanksPath);

  ASLSetupFile.Free;

end;// procedure TfrmSettings.ReadASLSetupFile

//========================================================================================
function TfrmSettings.ASLSettingsFileExists : boolean;
var
  vstrTStr : string;
begin
  vstrASLSettingsFileName := ASLDataPath + cstrASLSettingsFileName;
  Result := FileExists(vstrASLSettingsFileName);
end;// function ASLSettingsFileExists

//========================================================================================
procedure TfrmSettings.ReadASLSettingsFile;
var
  vstrTStr : string;
  vblnTbln : boolean;
begin

  vstrASLSettingsFileName := ASLDataPath + '/' + cstrASLSettingsFileName;
  ASLSettingsFile := TINIFile.Create(vstrASLSettingsFileName);

  // APPLICATION Section
  ASLPath := ASLSettingsFile.ReadString( cstrSectionApplication,
                                          cstrKeyASLPath,
                                          ASLPath);
  ASLDataPath := ASLSettingsFile.ReadString( cstrSectionApplication,
                                        cstrKeyASLDataPath,
                                        ASLDataPath);
  ASLTanksPath := ASLSettingsFile.ReadString( cstrSectionApplication,
                                        cstrKeyASLTanksPath,
                                        ASLTanksPath);

  vstrTStr := (ASLSettingsFile.Readstring( cstrSectionTankData,
                                        cstrKeyAutoloadLastTank,
                                        HUBoolToStr(AutoloadLastTank)));
  AutoloadLastTank := HUStrToBool(vstrTStr);

  if AutoloadLastTank then
    LastTank := (ASLSettingsFile.Readstring( cstrSectionTankData,
                                           cstrKeyLastTank,
                                           LastTank))
  else
    LastTank :='';

  vstrTStr := ASLSettingsFile.ReadString( cstrSectionApplication,
                                        cstrKeyDefaultLengthUnit,
                                        '');
  SetDefaultLengthUnitFromStr(vstrTStr);
  vstrTStr := ASLSettingsFile.ReadString( cstrSectionApplication,
                                        cstrKeyDefaultTemperatureUnit,
                                        '');
  SetDefaultTemperatureUnitFromStr(vstrTStr);
  vstrTStr := ASLSettingsFile.ReadString( cstrSectionApplication,
                                        cstrKeyDefaultVolumeUnit,
                                        '');
  SetDefaultVolumeUnitFromStr(vstrTStr);

  // TANK DATA Section
  vstrTStr := ASLSettingsFile.ReadString( cstrSectionTankData,
                                        cstrKeyDefaultTankType,
                                        '');
  frmTankTable.SetDefaultTankTypeFromStr(vstrTStr);

  vstrTStr := ASLSettingsFile.ReadString( cstrSectionTankData,
                                        cstrKeyDefaultTankLengthUnit,
                                        '');
  frmTankTable.SetDefaultTankLengthUnitFromStr(vstrTStr);

  vstrTStr := ASLSettingsFile.ReadString( cstrSectionTankData,
                                        cstrKeyDefaultTankTemperatureUnit,
                                        '');
  frmTankTable.SetDefaultTankTemperatureUnitFromStr(vstrTStr);

  ASLSettingsFile.Free;

end;// procedure TfrmSettings.ReadASLSettingsFile

//========================================================================================
procedure TfrmSettings.WriteASLSettingsFile;
var
  vblbTbln : boolean;
  vstrTStr: string;
begin

  vstrASLSettingsFileName := ASLDataPath + '/' + cstrASLSettingsFileName;

  ASLSettingsFile := TINIFile.Create(vstrASLSettingsFileName);

  // APPLICATION Data Section

  ASLSettingsFile.WriteString( cstrSectionApplication,
                            cstrKeyASLPath,
                            ASLPath);
  ASLSettingsFile.WriteString( cstrSectionApplication,
                            cstrKeyASLDataPath,
                            ASLDataPath);
  ASLSettingsFile.WriteString( cstrSectionApplication,
                            cstrKeyASLTanksPath,
                            ASLTanksPath);

  vstrTStr := HUBoolToStr(AutoloadLastTank);

  ASLSettingsFile.WriteString( cstrSectionApplication,
                            cstrKeyAutoloadLastTank,
                            vstrTStr);

  ASLSettingsFile.WriteString( cstrSectionApplication,
                            cstrKeyLastTank,
                            LastTank);

 ASLSettingsFile.WriteString( cstrSectionApplication,
                              cstrKeyDefaultLengthUnit,
                              GetDefaultLengthUnitStr);

  ASLSettingsFile.WriteString( cstrSectionApplication,
                              cstrKeyDefaultTemperatureUnit,
                              GetDefaultTemperatureUnitStr);

  ASLSettingsFile.WriteString( cstrSectionApplication,
                              cstrKeyDefaultVolumeUnit,
                              GetDefaultVolumeUnitStr);

  ASLSettingsFile.WriteString( cstrSectionApplication,
                              cstrKeyDefaultVolumeUnit,
                              GetDefaultVolumeUnitStr);

   // TANK DATA Section

   ASLSettingsFile.WriteString( cstrSectionTankData,
                            cstrKeyDefaultTankType,
                            frmTankTable.GetDefaultTankTypeStr);

  ASLSettingsFile.WriteString( cstrSectionTankData,
                            cstrKeyDefaultTankLengthUnit,
                            frmTankTable.GetDefaultTankLengthUnitStr);

  ASLSettingsFile.WriteString( cstrSectionTankData,
                            cstrKeyDefaultTankTemperatureUnit,
                            frmTankTable.GetDefaultTankTemperatureUnitStr);

  ASLSettingsFile.WriteString( cstrSectionTankData,
                            cstrKeyDefaultTankVolumeUnit,
                            frmTankTable.GetDefaultTankVolumeUnitStr);

  ASLSettingsFile.Free;

end;// procedure TfrmSettings.WriteASLSettingsFile

//========================================================================================
//          COMMAND BUTTON ROUTINES
//========================================================================================
procedure TfrmSettings.bbtSaveClick(Sender: TObject);
begin

  // Save the APPLICATION Data
  AutoLoadLastTank := chkAutoLoadLastTank.Checked;

  DefaultLengthUnit := tLengthUnit(cbxDefaultLengthUnit.ItemIndex);
  DefaultTemperatureUnit := tTemperatureUnit(cbxDefaultTemperatureUnit.ItemIndex);
  DefaultVolumeUnit := tVolumeUnit(cbxDefaultVolumeUnit.ItemIndex);

  // Save the TANK Data
  frmTankTable.DefaultTankType := tTankType(cbxDefaultTankType.ItemIndex);
  frmTankTable.DefaultTankLengthUnit := tLengthUnit(cbxDefaultTankLengthUnit.ItemIndex);
  frmTankTable.DefaultTankTemperatureUnit := tTemperatureUnit(cbxDefaultTankTemperatureUnit.ItemIndex);
  frmTankTable.DefaultTankVolumeUnit := tVolumeUnit(cbxDefaultTankVolumeUnit.ItemIndex);

end;// procedure TfrmSettings.bbtSaveClick

//========================================================================================
procedure TfrmSettings.bbtCancelClick(Sender: TObject);
var
  vbytTemp: Byte;
begin

  if ConfirmationMessageDlg('Cancellation', 'Confirm you wish to Cancel ?') = mrYes then
  begin

     // Reset APPLICATION Data
     AutoloadLastTank := valOrigAutoloadLastTank;
     chkAutoLoadLastTank.Checked := AutoLoadLastTank;

     DefaultLengthUnit := vluOrigDefaultLengthUnit;
     cbxDefaultLengthUnit.Items.Clear;
     for vbytTemp := 0 to tLengthUnitArrayMaxEntries do
       cbxDefaultLengthUnit.Items.Add(LengthUnitArray[vbytTemp]);
     cbxDefaultLengthUnit.ItemIndex := ord(frmSettings.DefaultLengthUnit);

     DefaultTemperatureUnit := vtuOrigDefaultTemperatureUnit;
     cbxDefaultTemperatureUnit.Items.Clear;
     for vbytTemp := 0 to tTemperatureUnitArrayMaxEntries do
       cbxDefaultTemperatureUnit.Items.Add(TemperatureUnitArray[vbytTemp]);
     cbxDefaultTemperatureUnit.ItemIndex := ord(frmSettings.DefaultTemperatureUnit);

     DefaultVolumeUnit := vvuOrigDefaultVolumeUnit;
     cbxDefaultVolumeUnit.Items.Clear;
     for vbytTemp := 0 to tVolumeUnitArrayMaxEntries do
       cbxDefaultVolumeUnit.Items.Add(VolumeUnitArray[vbytTemp]);
     cbxDefaultVolumeUnit.ItemIndex := ord(frmSettings.DefaultVolumeUnit);

     // Reset TANK Data
     frmTankTable.DefaultTankType := vttOrigDefaultTankType;
     frmTankTable.DefaultTankLengthUnit := vluOrigDefaultTankLengthUnit;
     frmTankTable.DefaultTankTemperatureUnit := vtuOrigDefaultTankTemperatureUnit;
     frmTankTable.DefaultTankVolumeUnit := vvuOrigDefaultTankVolumeUnit;

  end
  else
  begin
    showmessage('Dont Cancel');
    ModalResult := mrNone;
    Exit;
  end;// if ConfirmationMessageDlg

end;// procedure TfrmSettings.bbtCancelClick

//========================================================================================
//          CONTROL ROUTINES
//========================================================================================

//========================================================================================
//          TOOLBAR ROUTINES
//========================================================================================

//========================================================================================
//           STATUSBAR ROUTINES
//========================================================================================

//========================================================================================
//          DATABASE ROUTINES
//========================================================================================

//=========================
//  OnChange Routines
//=========================

//=========================
//  OnClick Routines
//=========================

//=========================
//  OnKeypress Routines
//=========================

//========================================================================================
//          FORM ROUTINES
//========================================================================================
procedure TfrmSettings.FormCreate(Sender: TObject);
begin
  // Set the Initial Default values
  frmSettings.SetAutoLoadLastTank(True);
  frmSettings.SetLastTank('');
end;// procedure TfrmSettings.FormCreate

//========================================================================================
procedure TfrmSettings.FormShow(Sender: TObject);
var
  vbytTemp: byte;
begin

  // Save Original Data in case we Cancel
  // APPLICATION Data
  vluOrigDefaultLengthUnit := DefaultLengthUnit;
  vtuOrigDefaultTemperatureUnit := DefaultTemperatureUnit;
  vvuOrigDefaultVolumeUnit := DefaultVolumeUnit;
  valOrigAutoloadLastTank := AutoloadLastTank;

  // TANK Data
  vttOrigDefaultTankType := frmTankTable.GetDefaultTankType;
  vluOrigDefaultTankLengthUnit := frmTankTable.GetDefaultTankLengthUnit;
  vtuOrigDefaultTankTemperatureUnit := frmTankTable.GetDefaultTankTemperatureUnit;
  vvuOrigDefaultTankVolumeUnit := frmTankTable.GetDefaultTankVolumeUnit;

  // Initialize the Application Data tab
  edtApplicationPath.Text := ApplicationPath;
  edtASLPath.Text := ASLPath;
  edtASLDataPath.Text := ASLDataPath;
  edtASLTanksPath.Text := ASLTanksPath;

  cbxDefaultLengthUnit.Items.Clear;
  for vbytTemp := 0 to tLengthUnitArrayMaxEntries do
    cbxDefaultLengthUnit.Items.Add(LengthUnitArray[vbytTemp]);
  cbxDefaultLengthUnit.ItemIndex := ord(frmSettings.DefaultLengthUnit);

  cbxDefaultTemperatureUnit.Items.Clear;
  for vbytTemp := 0 to tTemperatureUnitArrayMaxEntries do
    cbxDefaultTemperatureUnit.Items.Add(TemperatureUnitArray[vbytTemp]);
  cbxDefaultTemperatureUnit.ItemIndex := ord(frmSettings.DefaultTemperatureUnit);

  cbxDefaultVolumeUnit.Items.Clear;
  for vbytTemp := 0 to tVolumeUnitArrayMaxEntries do
    cbxDefaultVolumeUnit.Items.Add(VolumeUnitArray[vbytTemp]);
  cbxDefaultVolumeUnit.ItemIndex := ord(frmSettings.DefaultVolumeUnit);

  chkAutoLoadLastTank.Checked := frmSettings.AutoLoadLastTank;

  // Initialize the Tank Data tab
  cbxDefaultTankType.Items.Clear;
  for vbytTemp := 0 to tTankTypeArrayMaxEntries do
    cbxDefaultTankType.Items.Add(frmTankTable.TankTypeArray[vbytTemp]);
  cbxDefaultTankType.ItemIndex := ord(frmTankTable.DefaultTankType);

  cbxDefaultTankLengthUnit.Items.Clear;
  for vbytTemp := 0 to tLengthUnitArrayMaxEntries do
    cbxDefaultTankLengthUnit.Items.Add(frmTankTable.TankLengthUnitArray[vbytTemp]);
  cbxDefaultTankLengthUnit.ItemIndex := ord(frmTankTable.DefaultTankLengthUnit);

  cbxDefaultTankTemperatureUnit.Items.Clear;
  for vbytTemp := 0 to tTemperatureUnitArrayMaxEntries do
    cbxDefaultTankTemperatureUnit.Items.Add(frmTankTable.TankTemperatureUnitArray[vbytTemp]);
  cbxDefaultTankTemperatureUnit.ItemIndex := ord(frmTankTable.DefaultTankTemperatureUnit);

  cbxDefaultTankVolumeUnit.Items.Clear;
  for vbytTemp := 0 to tVolumeUnitArrayMaxEntries do
    cbxDefaultTankVolumeUnit.Items.Add(frmTankTable.TankVolumeUnitArray[vbytTemp]);
  cbxDefaultTankVolumeUnit.ItemIndex := ord(frmTankTable.DefaultTankVolumeUnit);

end;// procedure TfrmSettings.FormShow

//========================================================================================
end.// unit ApplicationSettings

